{"version":3,"file":"static/chunks/pages/college-bookstores/[state]-7427e5e7c7ffbdd5.js","mappings":"oKA0FA,UAAeA,EAAf,G,uBCzFKC,OAAOC,SAAWD,OAAOC,UAAY,IAAIC,KAAK,CAC7C,8BACA,WACE,OAAO,EAAQ,Y","sources":["webpack://_N_E/./src/pages/college-bookstores/[state].js","webpack://_N_E/?0f3c"],"sourcesContent":["import fs from \"fs\";\nimport http from \"api\";\nimport path from \"path\";\n\nimport { isObject } from \"common/utils\";\nimport { BookstoresByStateLanding } from \"modules/Bookstores\";\nimport { replaceURLWhitespace } from \"modules/Bookstores/utils\";\n\nconst errorHandler = (err) => {\n    if (err) throw err;\n};\n\nconst filePath = path.join(process.cwd(), \"public/data/bookStoresData.json\");\n\nconst setParamsData = (data) => {\n    fs.writeFileSync(filePath, JSON.stringify(data), errorHandler);\n};\n\nconst getParamsData = () => {\n    const data = fs.readFileSync(filePath, errorHandler);\n    const dataObj = JSON.parse(data);\n\n    return dataObj;\n};\n\nexport const getStaticPaths = async () => {\n    const storesByStates = await http.getBookstoresCountByStates();\n\n    const paths = storesByStates.map(({ state: { name } }) => ({\n        params: {\n            state: replaceURLWhitespace(name)\n        }\n    }));\n\n    const additionalData = storesByStates.reduce((acc, { state: { name, abbreviation } }) => {\n        acc[replaceURLWhitespace(name)] = { name, abbreviation };\n\n        return acc;\n    }, {});\n\n    setParamsData(additionalData);\n\n    return { paths, fallback: false };\n};\n\nexport const getStaticProps = async (context) => {\n    const {\n        params: { state }\n    } = context;\n\n    const statesData = getParamsData();\n    const { name, abbreviation } = statesData[state];\n\n    const storesByState = await http.getBookstoresByState({\n        params: { itemsPerPage: 200, \"state.abbreviation\": abbreviation }\n    });\n\n    const bookstoresByState = storesByState.map(\n        ({\n            name,\n            website,\n            phone,\n            email,\n            address: {\n                state: { abbreviation },\n                postcode,\n                lines,\n                city\n            }\n        }) => ({\n            name,\n            website,\n            phone,\n            email,\n            address: {\n                firstLine: Array.isArray(lines)\n                    ? lines\n                    : isObject(lines)\n                    ? Object.values(lines)\n                    : [],\n                secondLine: `${city} ${abbreviation}, ${postcode}`\n            }\n        })\n    );\n\n    return {\n        props: { stateName: name, storesByState: bookstoresByState }\n    };\n};\n\nexport default BookstoresByStateLanding;\n","\n    (window.__NEXT_P = window.__NEXT_P || []).push([\n      \"/college-bookstores/[state]\",\n      function () {\n        return require(\"private-next-pages/college-bookstores/[state].js\");\n      }\n    ]);\n    if(module.hot) {\n      module.hot.dispose(function () {\n        window.__NEXT_P.push([\"/college-bookstores/[state]\"])\n      });\n    }\n  "],"names":["BookstoresByStateLanding","window","__NEXT_P","push"],"sourceRoot":""}